package com.myy.auth.controller;

import com.myy.auth.service.UserService;
import com.myy.auth.vo.LoginUser;
import com.myy.auth.vo.PasswordVo;
import com.myy.auth.vo.SessionUser;
import com.myy.common.result.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户接口
 */
@AllArgsConstructor
@RestController
@RequestMapping("user")
public class UserController {

    private final UserService userService;

    /**
     * 用户登录
     */
    @PostMapping("login")
    public Result<SessionUser> login(@RequestBody LoginUser user) {
        return Result.success(userService.login(user));
    }

    /**
     * 退出登录
     */
    @GetMapping("logout")
    public Result<String> logout(String token) {
        return Result.success(userService.logout(token));
    }

    /**
     * 修改密码
     */
    @PostMapping("changePwd")
    public Result<String> changePwd(@RequestBody PasswordVo vo) {
        return Result.success(userService.changePwd(vo));
    }
}
